<?php

/**
 * @filename swoole_lock.php 
 * @encoding UTF-8 
 * @author  fwz 
 * @datetime 2018-6-13  10:35:11
  */


//创建锁对象
$lock = new swoole_lock();
echo "[master] creat  lock \n ";

$lock->lock(); //开始锁定，主进程

if(pcntl_fork() > 0){
    sleep(2);
    $lock->unlock(); //解锁
}else{
    
    echo "[Child] Wait Lock\n";
    $lock->lock();
    echo "[Child] Get Lock\n";
    $lock->unlock();
    exit("[Child] exit\n");
    
}

echo "[Master]release lock\n";
unset($lock);
sleep(1);
echo "[Master]exit\n";



